import request from '../index'
import { IAccount, ILoginResult } from './type'
import { IDataType } from '../types'

enum LoginAPI {
  AccountLogin = '/login',
  UserInfo = '/users/', // /users/1
  UserMenus = '/role/' // /role/1/menu
}

// 请求账号登录信息
export function accountLoginRequest(account: IAccount) {
  return request.post<IDataType<ILoginResult>>({
    url: LoginAPI.AccountLogin,
    data: account
  })
}

// 请求用户信息
export function requestUserInfoById(id: number) {
  return request.get<IDataType>({
    url: LoginAPI.UserInfo + id,
    showLoading: false
  })
}

// 请求角色菜单树
export function requestUserMenusByRoleId(roleId: number) {
  return request.get<IDataType>({
    url: LoginAPI.UserMenus + roleId + '/menu',
    showLoading: false
  })
}
